package com.junzhiit.nengji.cms.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class SpringAsyncConfig {
	
	// 核心线程数
	private final int CORE_POOL_SIZE = 10;
	
	// 最大线程数
	private final int MAX_POOL_SIZE = 100;
	
	// 线程池所使用的缓冲队列
	private final int QUEUE_CAPACITY = 50;
	
	// 线程池维护线程所允许的空闲时间
	private final int KEEP_ALIVE_SECONDS = 300;

	@Bean
    public AsyncTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(MAX_POOL_SIZE);
        executor.setCorePoolSize(CORE_POOL_SIZE);
        executor.setQueueCapacity(QUEUE_CAPACITY);
        executor.setKeepAliveSeconds(KEEP_ALIVE_SECONDS);// 空闲时间
        return executor;
    }
}
